<?php
/*
ajax 登录返回代码提示
0.验证码错误
1.用户名不合法
2.密码不能为空
3.用户名不存在
4.密码错误
5.管理员帐号不允许从前台登录！
6.登录成功
7.成功退出登录
*/
require_once(dirname(__FILE__)."/config.php");
if(empty($dopost)) $dopost = '';
if(empty($fmdo)) $fmdo = '';

/*********************
function check_email()
*******************/
if($fmdo=='ajaxlogin')
{
    //用户登录
    if($dopost=="send")
    {
       
        if(CheckUserID($userid,'',false)!='ok')
        {
			if($myset=='ajax')die('1');
            ShowMsg("你输入的用户名 {$userid} 不合法！","-1");
            exit();
        }
		if($userid=='') {
			if($myset=='ajax')die('6');
            ShowMsg("用户名不能为空！", "-1", 0, 2000);
            exit();
        }
        if($pwd=='')
        {
			if($myset=='ajax')die('2');
            ShowMsg("密码不能为空！","-1",0,2000);
            exit();
        }

        //检查帐号
        $rs = $cfg_ml->CheckUser($userid,$pwd);  
        if($rs==0)
        {
			if($myset=='ajax')die('3');
            ShowMsg("用户名不存在！", "-1", 0, 2000);
            exit();
        }
        else if($rs==-1) {
			if($myset=='ajax')die('4');
            ShowMsg("密码错误！", "-1", 0, 2000);
            exit();
        }
        else if($rs==-2) {
			if($myset=='ajax')die('5');
            ShowMsg("管理员帐号不允许从前台登录！", "-1", 0, 2000);
            exit();
        }
        else
        {
            // 清除会员缓存
            $cfg_ml->DelCache($cfg_ml->M_ID);
            if(empty($gourl) || preg_match("#action|_do#i", $gourl))
            {
				if($myset=='ajax')die('7');
                ShowMsg("成功登录，5秒钟后转向系统主页...","index.php",0,2000);
            }
            else
            {
                $gourl = str_replace('^','&',$gourl);
				if($myset=='ajax')die('6');
                ShowMsg("成功登录，现在转向指定页面...",$gourl,0,2000);
            }
            exit();
        }
    }
    //退出登录
    else if($dopost=="exit")
    {
		$cfg_ml->ExitCookie();
		if($myset=='ajax')die('7');
        ShowMsg("成功退出登录！","index.php",0,2000);
        exit();
    }
}
else
{
    ShowMsg("本页面禁止返回!","index.php");
}